package com.example.demo.business.service;

import com.example.demo.base.bean.Meta;
import com.example.demo.base.exceptions.BaseException;
import com.example.demo.business.bean.entity.HUser;
import com.example.demo.business.dao.HUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TokenService {
    @Autowired
    private HUserDao hUserDao;

    public int getUidByToken(String token){
        HUser hUser = hUserDao.findByAccessToken(token);
        if (hUser==null) throw new BaseException(Meta.TokenExpire);
        return hUser.getId();
    }

    public HUser getUserInfoByToken(String token){
        HUser hUser = hUserDao.findByAccessToken(token);
        if (hUser==null) throw new BaseException(Meta.TokenExpire);
        return hUser;
    }
    //更新用户信息
    public void updateUserInfo(HUser hUser){
        hUserDao.save(hUser);
    }
}
